﻿<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <title>报废品查询报表</title>
</head>

<body>
  <div id="app" v-cloak v-on:keyup.enter="getData">
    <!-- 报表标题 -->
    <vue2-report-header :title="'报废品查询报表'"></vue2-report-header>
    <div style="padding:10px;">
      <!-- 查询条件区 -->
      <el-form :inline="true" :model="queryInfo" ref="queryInfoRef" style="margin: 10px" :label-position="'left'">
        <el-form-item label="主制分厂:">
          <el-select v-model="queryInfo.factoryid" placeholder="请选择分厂" clearable filterable @change="bindControl">
            <el-option v-for="f in factoryList" :key="f.factoryid" :label="f.factoryname" :value="f.factoryid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="承制分厂:">
          <el-select v-model="queryInfo.tofactoryid" placeholder="请选择分厂" clearable filterable>
            <el-option v-for="f in factoryList" :key="f.factoryid" :label="f.factoryname" :value="f.factoryid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="工区:">
          <el-select v-model="queryInfo.workcenterid" placeholder="请选择工区" clearable filterable>
            <el-option v-for="w in searchWorkcenterList" :key="w.workcenterid" :label="w.workcentername"
              :value="w.workcenterid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="操作工:">
          <el-select v-model="queryInfo.workerid" placeholder="请选择操作工" clearable filterable>
            <el-option v-for="w in factoryUsers" :key="w.employeeid" :label="w.fullname" :value="w.employeeid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="检验员:">
          <el-select v-model="queryInfo.checkerid" placeholder="请选择检验员" clearable filterable>
            <el-option v-for="w in checkerList" :key="w.employeeid" :label="w.fullname" :value="w.employeeid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="机型:">
          <el-select v-model="queryInfo.productfamilyname" placeholder="请选择机型" clearable filterable>
            <el-option v-for="i in productFamilyList" :key="i.productfamilyname" :label="i.productfamilyname"
              :value="i.productfamilyname">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item prop='mfgordername' label="订单号:">
          <el-autocomplete v-model.trim="queryInfo.mfgordername" placeholder="请输入订单号" :trigger-on-focus="false"
            style="width:240px;" :fetch-suggestions="searchMfgorderAsync" :value-key="'mfgordername'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item prop='productname' label="零件图号:">
          <el-autocomplete v-model.trim="queryInfo.productname" placeholder="请输入零件图号" :trigger-on-focus="false"
            style="width:240px;" :fetch-suggestions="searchProductAsync" :value-key="'productname'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item prop='containername' label="流水卡号:">
          <el-autocomplete v-model.trim="queryInfo.containername" placeholder="请输入流水卡号" :trigger-on-focus="false"
            style="width:240px;" :fetch-suggestions="searchContainerAsync" :value-key="'containername'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item label="报废时间:">
          <el-date-picker v-model="queryInfo.createDate" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="small" @click="getData">查询</el-button>
          <el-button type="primary" icon="el-icon-download" size="small" @click="getExportExcel">导出</el-button>
        </el-form-item>
      </el-form>

      <!-- 表格 -->
      <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
        element-loading-background="rgba(0,0,0,0.8)" :data="dataList" stripe border show-overflow-tooltip>
        <el-table-column type="index" width="40"></el-table-column>
        <el-table-column prop="factoryname" label="主制分厂" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column prop="workcentername" label="工区" width="120" show-overflow-tooltip></el-table-column>
        <el-table-column prop="tofactoryname" label="承制分厂" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column prop="productfamily" label="机型" width="80" show-overflow-tooltip></el-table-column>
        <el-table-column prop="mfgordername" label="订单号" width="120" show-overflow-tooltip></el-table-column>
        <el-table-column prop="productname" label="零件图号" width="120" show-overflow-tooltip></el-table-column>
        <el-table-column prop="containername" label="流水卡号" show-overflow-tooltip></el-table-column>
        <el-table-column prop="childcontainername" label="子批次号" width="100" show-overflow-tooltip>
          <template scope="scope">
            <div v-if="scope.row.childcontainername">
              {{scope.row.childcontainername.split('/')[1]}}
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="workflowstepname" label="工序" width="120" show-overflow-tooltip></el-table-column>
        <el-table-column prop="scrapqty" label="报废数" width="60" show-overflow-tooltip></el-table-column>
        <el-table-column prop="reportperson" label="操作工" width="80" show-overflow-tooltip></el-table-column>
        <el-table-column prop="checker" label="检验员" width="80" show-overflow-tooltip></el-table-column>
        <el-table-column prop="checkvalidatedate" label="检验时间" width="160" :formatter="replaceDate"
          show-overflow-tooltip></el-table-column>
        <el-table-column prop="zzrz" label="责任者" width="80" show-overflow-tooltip>
          <template scope="scope">
            <div v-if="scope.row.zzrz">
              <el-tag>{{scope.row.zzrz}}</el-tag>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="lossreasonname" label="报废原因" width="160" show-overflow-tooltip></el-table-column>
        <el-table-column prop="zzfplx" label="废品类型" width="120" show-overflow-tooltip></el-table-column>
      </el-table>

      <!-- 分页 -->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="queryInfo.currentPage" :page-sizes="[10,20,50]" :page-size="queryInfo.pageSize"
        layout="prev,pager,next,jumper,sizes,total" :total="total">
      </el-pagination>

      <!-- 回到顶部 -->
      <el-backtop></el-backtop>
    </div>
  </div>

  <script type="module">
    import { fetchSuggestion, exportExcelData } from '../Scripts/hooks/useCommonMethod.js'
    import { getProductFamily, getFactoryUsersByRoleName, getFactoryUsers } from '../Scripts/hooks/fetchAPI.js'
    import { prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth } from '../Scripts/hooks/useDateShortCut.js'
    import { replaceDate, splitDate } from '../Scripts/hooks/format.js'
    import Vue2ReportHeader from '../Scripts/components/Vue2ReportHeader.js'
    const app = new Vue({
      el: '#app',
      components: { Vue2ReportHeader },
      data: {
        loading: false,
        loadingText: '数据加载中...',
        total: 0,
        factoryList: [],
        workcenterList: [],//所有工区
        searchWorkcenterList: [],
        productFamilyList: [],// 机型
        checkerList: [],// 分厂检验员
        factoryUsers: [],// 分厂员工
        queryInfo: {
          factoryid: '',//主制分厂
          tofactoryid: '',//承制分厂
          workcenterid: '',// 工区
          workerid: '',// 操作工
          checkerid: '',// 检验员
          productfamilyname: '',// 机型
          mfgordername: '',// 订单号
          productname: '',// 零件图号
          containername: '',// 流水卡号
          createDate: '',// 报废时间
          currentPage: 1,//当前页
          pageSize: 10//每页显示条数
        },
        dataList: [],
        pickerOptions: { shortcuts: [prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth] },
        replaceDate,
      },
      methods: {
        // 查询订单号
        searchMfgorderAsync(value, callback) {
          fetchSuggestion({ actionName: 'getMfgordernameAsync', name: 'mfgordername', value, callback });
        },
        // 查询件号
        searchProductAsync(value, callback) {
          fetchSuggestion({ actionName: 'getProductnameAsync', name: 'productname', value, callback });
        },
        // 查询批次号
        searchContainerAsync(value, callback) {
          fetchSuggestion({ actionName: 'getContainernameAsync', name: 'containername', value, callback });
        },
        // 查询数据
        async getData() {
          this.loading = true;
          this.loadingText = '数据查询中...';
          const { data: { data, meta, total } } = await axios.post('../handler/report/ScrapReport.ashx?action=getData', {
            ...this.queryInfo,
            type: 'getData'
          })
          this.loading = false;//请求结束，关闭加载中动画
          if (meta.status === 500) {
            return this.$message.error(meta.msg);
          }
          this.dataList = data;
          this.total = total;
        },
        // 导出excel
        async getExportExcel() {
          const config = {
            url: '../handler/report/ScrapReport.ashx?action=exportExcel',
            data: { type: 'exportExcel', ...this.queryInfo }
          }
          exportExcelData(config, this);
        },
        //查询工区
        async getWorkcenter() {
          const { data: { data, meta, total } } = await axios.post('../handler/report/CommonHandler.ashx', {
            type: 'getWorkcenter'
          });

          this.workcenterList = data;//缓存所有工区信息
          let obj = {};
          let f = data.map(item => {
            return {
              factoryid: item.factoryid,
              factoryname: item.factoryname
            }
          })
          //缓存去重后的分厂信息
          this.factoryList = f.reduce(function (item, next) {
            obj[next.factoryid] ? '' : obj[next.factoryid] = true && item.push(next);
            return item;
          }, []);
        },
        //监听 页码值 改变的事件
        handleCurrentChange(newPage) {
          this.queryInfo.currentPage = newPage;
          this.getData();
        },
        //监听 pagesize 改变的事件
        handleSizeChange(newSize) {
          this.queryInfo.pageSize = newSize;
          this.getData();
        },
        //绑定 【查询区】 对话框中的工区下拉框
        async bindControl(val) {
          // 清除已选择工区
          this.queryInfo.workcenterid = null
          // 清除已选择检验员
          this.queryInfo.checkerid = null
          // 清除已选择操作工
          this.queryInfo.workerid = null

          if (val) {
            // 从缓存中过滤工区
            this.searchWorkcenterList = this.workcenterList.filter(item => {
              return item.factoryid === val
            })
            this.checkerList = await getFactoryUsersByRoleName({ factoryid: val, rolename: '检验员' });
            this.factoryUsers = await getFactoryUsers({ factoryid: val });
          }
        }
      },
      async mounted() {
        this.getWorkcenter();
        this.productFamilyList = await getProductFamily();
      },
      watch: { queryInfo: { handler() { this.queryInfo.currentPage = 1 }, deep: true } }
    })
  </script>
</body>

</html>